<?php
/* config file for general configs */
require_once("../config.php");

/* use the database for queries */
require_once("../class/database.class.php");

/* blog class for site ident */
require_once("../class/blog.class.php");

/* create an instance of the blog */
$b = new blog($_SERVER["HTTP_HOST"]);

// write the xml header first
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><list>";

// create the xml output for the categories
$catlist = $b->db->getCategoryPublishedList();
for($cat=0;$cat<count($catlist);$cat++){
	$catitem = $b->db->getCategory($catlist[$cat]["url"]);
	$xml .= "<category>"
			."<url><![CDATA[".$catlist[$cat]["url"]."]]></url>"
			."<name><![CDATA[".$catitem[0]["name"]."]]></name>"
			."<body><![CDATA[".$catitem[0]["body"]."]]></body>"
			."</category>";
}

// create the xml output for the articles
$categoryList = $b->db->getArticleCategoryList();
$articleList = $b->getLatestArticles(99999999);
for($a=0; $a<count($articleList);$a++){
	$articleItem = $b->getArticle($articleList[$a]["url"]);
	$xml .= "<article>"
			."<title><![CDATA[".$articleList[$a]["title"]."]]></title>"
			."<url><![CDATA[".$articleList[$a]["url"]."]]></url>"
			."<date timestamp=\"".$articleList[$a]["date_ts"]."\"><![CDATA["
			.$articleList[$a]["date"]."]]></date>"
			."<image url=\"http://".CONFIG_CDN_PRIMARY_DOMAIN."/img/".$articleItem["image"]."\" />"
			."<content><![CDATA[".$articleItem["formatted_body"]."]]></content>"
			."<keyword><![CDATA[".$articleList[$a]["keyword"]."]]></keyword>"
			."<author>"
			."<firstname><![CDATA[".$articleList[$a]["author_firstname"]."]]></firstname>"
			."<lastname><![CDATA[".$articleList[$a]["author_lastname"]."]]></lastname>"
			."</author><categorylist>";
			
	// add all category associations
	for($c=0;$c<count($categoryList);$c++){
		if($categoryList[$c]["article_url"]==$articleList[$a]["url"]){
			$xml .= "<category url=\"".$categoryList[$c]["category_url"]."\" />";
		}
	}
			
	$xml .= "</categorylist></article>";
}
$xml .= "</list>";

header("Content-type: text/xml");
echo $xml;
?>